#include <iostream>
#include <string>
using namespace std;

class Pet {
	string pname;
public:
	Pet(const string& name) : pname(name) {}
	
	virtual string name( ) const { 
		return pname; 
	}
	
	virtual string description( ) const 
	{ return "This is " + pname; }
	
};


class Dog : public Pet {
	string favoriteActivity;
public:
	Dog(const string& name, const string& activity)
	: Pet(name), favoriteActivity(activity) {}
	
	virtual string description( ) const { 
		return Pet::name( ) + " likes to " + favoriteActivity; 
	}
};

//如果不使用指针*或者引用&，调用virtual方法可能会出现危险
void describe1(Pet a) { // Slices the object
	cout << a.description() << endl; 
}

void describe2(Pet& p) //
{ 
	cout << p.description() << endl; 
}

int main( ) 
{
	Pet p("Zhang");
	Dog d("Li", "sleep"); 
	
	describe1(p);
	describe1(d);// This is Li
	cout << "===================" << endl;
	
	describe2(p);
	describe2(d);// Li likes to sleep
}